package com.baosight.sczx.zm.cg.service;

import java.util.HashMap;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.threadlocal.UserSession;
import com.baosight.iplat4j.ep.ServiceEPBase;
import com.baosight.sczx.common.zm.basetools.StaticTools;
import com.baosight.sczx.common.zm.basetools.TablePk;
import com.baosight.sczx.zm.cg.domain.ZMCGDispatchDaily;
/**
 * 矿生产调度主表
 */
public class ServiceZMCG80 extends ServiceEPBase {
	/**
	 * <p>Function:initLoad</p>
	 * <p>Description: 初始化</p> 
	 */
	@Override
	public EiInfo initLoad(EiInfo inInfo) {
		inInfo.addBlock(EiConstant.resultBlock).set("showCount", "true");//如果不加这个，翻页的统计和显示是错误的
//		inInfo.addBlock(Department.getInstance().getConstructionUnit("cmes.cp.department", "orgCode", "orgName", false));
		EiInfo outInfo = this.query(inInfo);
		return outInfo;
//		return inInfo;
	}	
	
	/**
	 * <p>Function: query</p>
	 * <p>Description: 查询</p>
	 * <p>return value: ServiceZMCG80</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-10-21下午03:26:59 张小飞
	 *    
	 *    
	 * </p>
	 *
	 */
	@Override
	public EiInfo query(EiInfo inInfo) {
		String date = (String)inInfo.get("fdVirtualDate");
		StaticTools.setQueryParameters(inInfo, "fdVirtualDate",date, true);
		EiInfo outInfo = super.query(inInfo, "ZMCGDispatchDaily.query", new ZMCGDispatchDaily());
//		System.out.println("========================"+outInfo.getCellStr("result", 0, "fdMovelengthDay"));
//		System.out.println("========================"+outInfo.getCellStr("result", 0, "fdKeyId"));
		//outInfo.addBlock(Department.getInstance().getMiningDepts("cmes.cp.department", "orgCode", "orgName", false,UserSession.getInSessionProperty("miningCode").toString()));
		outInfo.set("fdCreatorId", UserSession.getUserId());//登录人的默认值
		outInfo.set("fdCreator", UserSession.getInSessionProperty("UserCname"));
		outInfo.set("fdCreateDepartmentId", UserSession.getInSessionProperty("orgCode"));//单位的默认值		
		outInfo.set("fdCreateDepartment", UserSession.getInSessionProperty("orgName"));//单位的默认值
		return outInfo;
	}
	/**
	 * 新增
	 * <p>Function: insert</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCP70</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-7-6下午03:58:15 张志芳
	 * </p>
	 *
	 */ 
	@Override
	public EiInfo insert(EiInfo inInfo) {	
		EiInfo out=new EiInfo();
		ZMCGDispatchDaily _dom = new ZMCGDispatchDaily();
		EiBlock eiBlock = inInfo.getBlock("result");
		eiBlock.setBlockMeta(_dom.eiMetadata);
		int rowcount = eiBlock.getRowCount();
		int i = 0;		
		for (; i < rowcount; i++) {
			_dom.fromMap(eiBlock.getRow(i));
			Map<String, String>	params = new HashMap<String, String>();
	
			_dom.setFdKeyId(TablePk.getInstance().getNextValue("T_CG_DISPATCHDAILY"));//主键			
			this.dao.insert("ZMCGDispatchDaily.insert",_dom);
		}		
		out = this.query(inInfo);
		out.setStatus(1);
		out.setMsg("操作" + rowcount + "记录成功");
		return out; 	
			
	}
} 